﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringDefs.Tests
{
    using NUnit.Framework;
    using StringDefs.Grammar;

    [TestFixture]
    public class GrammarTests
    {
        public class TheIsPalindromeMethod
        {
            static string[] palindromes = new string[] {"malayalam", "A but tuba.", "A Toyota! Race fast, safe car! A Toyota!",                                                    
                                                    "Doc, note, I Dissent. A fast never prevents a fatness. I diet on cod.", 
                                                    "Kay, a red nude, peeped under a yak.",
                                                    "Top step’s pup’s pet spot."
                                                    };


            [Test, TestCaseSource("palindromes")]
            public void ReturnsTrueForValidString(string palindrome)
            {
                Assert.True(palindrome.IsPalindrome());
            }

            static string[] invalidPalindromes = new string[] { "malay", "sundaram", "Vissi" };

            [Test, TestCaseSource("invalidPalindromes")]
            public void ReturnsFalseForInvalidString(string nonPalindrome)
            {
                Assert.False(nonPalindrome.IsPalindrome());
            }

        }

        public class TheIsAnagramMethod
        {
            static object[] anagramCases =
            {
            new string[] { "Motley Crue", "Me Cruel Toy" },
            new string[] { "Tom Cruise", "So Im Cuter" },
            new string[] { "Howard Stern", "Retard Shown" },
            new string[] { "TS Eliot", "toilets" },
            new string[] { "madonna louise ciccone", "one cool dance musician" },
            new string[] { "Why do you care", "Hey you coward"},
            new string[] { "Snooze Alarms", "Alas No More Zs"},
            new string[] { "Justin Timberlake", "im a jerk but listen"}
            };

            [Test, TestCaseSource("anagramCases")]
            public void ReturnsTrueForValidAnagrams(string a, string b)
            {
                Assert.True(a.IsAnagram(b));
            }

            static object[] invalidAnagramCases =
            {
                new string[] { "Motley Crue", "Me Crel Toy" },
                new string[] { "Tom Cruise", "So Am Cuter" },
                new string[] { "Howard' Stern", "Retard Shown" },
                new string[] { "T.S Eliot", "toilets" },
                new string[] { "madonna louise cccone", "one cool dance musician" },
                new string[] { "Why do you care!", "Hey you coward"},
                new string[] { "Snooze Alarms", "Alas! No More Zs"},
                new string[] { "Justin Timber", "Am a jerk but listen"}
            };

            [Test, TestCaseSource("invalidAnagramCases")]
            public void ReturnsFalseForNonAnagrams(string a, string b)
            {
                Assert.False(a.IsAnagram(b));
            }

        }

        public class TheIsHammingDistanceMethod
        {
            [Test]
            [ExpectedException(ExpectedMessage = "Hamming distance is only defined for strings of same length.")]
            public void ThrowsExceptionForInvalidStrings()
            {
                Grammar.HammingDistance("toned", "rose");
            }

            [Test]
            public void ReturnsCorrectDistanceForValidStrings()
            {
                Assert.AreEqual(3, Grammar.HammingDistance("toned", "roses"));
            }
        }
    }
}
